﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Ballgame.Model
{
    class Ballsimulation
    {
        public Ball ball;
        public Vector2 logicalPosition;

        public Ballsimulation() 
        {
        
            ball = new Ball();

        }

        internal void update(GameTime gameTime)
        {
            float m_elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            logicalPosition.X += m_elapsedTime * ball.ballSpeed.X;
            logicalPosition.Y += m_elapsedTime * ball.ballSpeed.Y;

            ball.setBallPosition(logicalPosition.X, logicalPosition.Y);
            BallCollision();
        }

        internal void BallCollision() 
        { 
            if(logicalPosition.X + ball.ballRadius > 1)
            {
                ball.ballSpeed.X = ball.ballSpeed.X * -1;
            
            }
            if (logicalPosition.Y + ball.ballRadius > 1)
            {
                ball.ballSpeed.Y = ball.ballSpeed.Y * -1;

            } 
            if (logicalPosition.X < 0)
            {
                ball.ballSpeed.X = ball.ballSpeed.X * -1;

            }
            if (logicalPosition.Y < 0)
            {
                ball.ballSpeed.Y = ball.ballSpeed.Y * -1;

            }

        
        }
    }
}
